using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Media;
namespace Microsoft.Expression.Drawing.Core
{
	internal static class PathGeometryHelper
	{
		private class AbbreviatedGeometryParser
		{
			private PathGeometry geometry;
			private PathFigure figure;
			private Point lastPoint;
			private Point secondLastPoint;
			private string buffer;
			private int index;
			private int length;
			private char token;
			public AbbreviatedGeometryParser(PathGeometry geometry)
			{
				this.geometry = geometry;
			}
			public void Parse(string data, int startIndex)
			{
				this.buffer = data;
				this.length = data.get_Length();
				this.index = startIndex;
				bool flag = true;
				IL_36D:
				while (this.ReadToken())
				{
					char c = this.token;
					if (flag)
					{
						if (c != 'M' && c != 'm')
						{
							throw new FormatException();
						}
						flag = false;
					}
					char c2 = c;
					if (c2 <= 'Z')
					{
						if (c2 <= 'M')
						{
							switch (c2)
							{
							case 'A':
								break;
							case 'B':
								goto IL_380;
							case 'C':
								goto IL_21C;
							default:
								if (c2 == 'H')
								{
									goto IL_168;
								}
								switch (c2)
								{
								case 'L':
									goto IL_F0;
								case 'M':
									goto IL_11E;
								default:
									goto IL_380;
								}
								break;
							}
						}
						else
						{
							switch (c2)
							{
							case 'Q':
								goto IL_2F1;
							case 'R':
								goto IL_380;
							case 'S':
								goto IL_32B;
							default:
								if (c2 == 'V')
								{
									goto IL_2A0;
								}
								if (c2 != 'Z')
								{
									goto IL_380;
								}
								goto IL_294;
							}
						}
					}
					else
					{
						if (c2 <= 'm')
						{
							switch (c2)
							{
							case 'a':
								break;
							case 'b':
								goto IL_380;
							case 'c':
								goto IL_21C;
							default:
								if (c2 == 'h')
								{
									goto IL_168;
								}
								switch (c2)
								{
								case 'l':
									goto IL_F0;
								case 'm':
									goto IL_11E;
								default:
									goto IL_380;
								}
								break;
							}
						}
						else
						{
							switch (c2)
							{
							case 'q':
								goto IL_2F1;
							case 'r':
								goto IL_380;
							case 's':
								goto IL_32B;
							default:
								if (c2 == 'v')
								{
									goto IL_2A0;
								}
								if (c2 != 'z')
								{
									goto IL_380;
								}
								goto IL_294;
							}
						}
					}
					do
					{
						Size size = this.ReadSize(false);
						double rotationAngle = this.ReadDouble(true);
						bool isLargeArc = this.ReadBool01(true);
						SweepDirection sweepDirection = this.ReadBool01(true) ? 1 : 0;
						this.lastPoint = this.ReadPoint(c, true);
						this.ArcTo(size, rotationAngle, isLargeArc, sweepDirection, this.lastPoint);
					}
					while (this.IsNumber(true));
					this.EnsureFigure();
					continue;
					IL_F0:
					this.EnsureFigure();
					do
					{
						this.lastPoint = this.ReadPoint(c, false);
						this.LineTo(this.lastPoint);
					}
					while (this.IsNumber(true));
					continue;
					IL_11E:
					this.lastPoint = this.ReadPoint(c, false);
					this.BeginFigure(this.lastPoint);
					char command = 'M';
					while (this.IsNumber(true))
					{
						this.lastPoint = this.ReadPoint(command, false);
						this.LineTo(this.lastPoint);
						command = 'L';
					}
					continue;
					IL_168:
					this.EnsureFigure();
					do
					{
						double num = this.ReadDouble(false);
						if (c == 'h')
						{
							num += this.lastPoint.get_X();
						}
						this.lastPoint.set_X(num);
						this.LineTo(this.lastPoint);
					}
					while (this.IsNumber(true));
					continue;
					IL_21C:
					this.EnsureFigure();
					do
					{
						Point point = this.ReadPoint(c, false);
						this.secondLastPoint = this.ReadPoint(c, true);
						this.lastPoint = this.ReadPoint(c, true);
						this.BezierTo(point, this.secondLastPoint, this.lastPoint);
					}
					while (this.IsNumber(true));
					continue;
					IL_294:
					this.FinishFigure(true);
					continue;
					IL_2A0:
					this.EnsureFigure();
					do
					{
						double num2 = this.ReadDouble(false);
						if (c == 'v')
						{
							num2 += this.lastPoint.get_Y();
						}
						this.lastPoint.set_Y(num2);
						this.LineTo(this.lastPoint);
					}
					while (this.IsNumber(true));
					continue;
					IL_2F1:
					this.EnsureFigure();
					do
					{
						Point point2 = this.ReadPoint(c, false);
						this.lastPoint = this.ReadPoint(c, true);
						this.QuadraticBezierTo(point2, this.lastPoint);
					}
					while (this.IsNumber(true));
					continue;
					IL_32B:
					this.EnsureFigure();
					while (true)
					{
						Point smoothBeizerFirstPoint = this.GetSmoothBeizerFirstPoint();
						Point point3 = this.ReadPoint(c, false);
						this.lastPoint = this.ReadPoint(c, true);
						this.BezierTo(smoothBeizerFirstPoint, point3, this.lastPoint);
						if (!this.IsNumber(true))
						{
							goto IL_36D;
						}
					}
					IL_380:
					throw new NotSupportedException();
				}
				this.FinishFigure(false);
			}
			private bool ReadToken()
			{
				this.SkipWhitespace(false);
				if (this.index < this.length)
				{
					this.token = this.buffer.get_Chars(this.index++);
					return true;
				}
				return false;
			}
			private Point ReadPoint(char command, bool allowComma)
			{
				double num = this.ReadDouble(allowComma);
				double num2 = this.ReadDouble(true);
				if (command >= 'a')
				{
					num += this.lastPoint.get_X();
					num2 += this.lastPoint.get_Y();
				}
				return new Point(num, num2);
			}
			private Size ReadSize(bool allowComma)
			{
				double num = this.ReadDouble(allowComma);
				double num2 = this.ReadDouble(true);
				return new Size(num, num2);
			}
			private bool ReadBool01(bool allowComma)
			{
				double num = this.ReadDouble(allowComma);
				if (num == 0.0)
				{
					return false;
				}
				if (num == 1.0)
				{
					return true;
				}
				throw new FormatException();
			}
			private double ReadDouble(bool allowComma)
			{
				if (!this.IsNumber(allowComma))
				{
					throw new FormatException();
				}
				bool flag = true;
				int i = this.index;
				if (this.index < this.length && (this.buffer.get_Chars(this.index) == '-' || this.buffer.get_Chars(this.index) == '+'))
				{
					this.index++;
				}
				if (this.index < this.length && this.buffer.get_Chars(this.index) == 'I')
				{
					this.index = Math.Min(this.index + 8, this.length);
					flag = false;
				}
				else
				{
					if (this.index < this.length && this.buffer.get_Chars(this.index) == 'N')
					{
						this.index = Math.Min(this.index + 3, this.length);
						flag = false;
					}
					else
					{
						this.SkipDigits(false);
						if (this.index < this.length && this.buffer.get_Chars(this.index) == '.')
						{
							flag = false;
							this.index++;
							this.SkipDigits(false);
						}
						if (this.index < this.length && (this.buffer.get_Chars(this.index) == 'E' || this.buffer.get_Chars(this.index) == 'e'))
						{
							flag = false;
							this.index++;
							this.SkipDigits(true);
						}
					}
				}
				if (flag && this.index <= i + 8)
				{
					int num = 1;
					if (this.buffer.get_Chars(i) == '+')
					{
						i++;
					}
					else
					{
						if (this.buffer.get_Chars(i) == '-')
						{
							i++;
							num = -1;
						}
					}
					int num2 = 0;
					while (i < this.index)
					{
						num2 = num2 * 10 + (int)(this.buffer.get_Chars(i) - '0');
						i++;
					}
					return (double)(num2 * num);
				}
				string text = this.buffer.Substring(i, this.index - i);
				double result;
				try
				{
					result = Convert.ToDouble(text, CultureInfo.get_InvariantCulture());
				}
				catch (FormatException)
				{
					throw new FormatException();
				}
				return result;
			}
			private void SkipDigits(bool signAllowed)
			{
				if (signAllowed && this.index < this.length && (this.buffer.get_Chars(this.index) == '-' || this.buffer.get_Chars(this.index) == '+'))
				{
					this.index++;
				}
				while (this.index < this.length && this.buffer.get_Chars(this.index) >= '0' && this.buffer.get_Chars(this.index) <= '9')
				{
					this.index++;
				}
			}
			private bool IsNumber(bool allowComma)
			{
				bool flag = this.SkipWhitespace(allowComma);
				if (this.index < this.length)
				{
					this.token = this.buffer.get_Chars(this.index);
					if (this.token == '.' || this.token == '-' || this.token == '+' || (this.token >= '0' && this.token <= '9') || this.token == 'I' || this.token == 'N')
					{
						return true;
					}
				}
				if (flag)
				{
					throw new FormatException();
				}
				return false;
			}
			private bool SkipWhitespace(bool allowComma)
			{
				bool result = false;
				while (this.index < this.length)
				{
					char c = this.buffer.get_Chars(this.index);
					char c2 = c;
					switch (c2)
					{
					case '\t':
					case '\n':
					case '\r':
						break;
					case '\v':
					case '\f':
						goto IL_49;
					default:
						if (c2 != ' ')
						{
							if (c2 != ',')
							{
								goto IL_49;
							}
							if (!allowComma)
							{
								throw new FormatException();
							}
							result = true;
							allowComma = false;
						}
						break;
					}
					IL_5B:
					this.index++;
					continue;
					IL_49:
					if (c > ' ' && c <= 'z')
					{
						return result;
					}
					if (char.IsWhiteSpace(c))
					{
						goto IL_5B;
					}
					return result;
				}
				return false;
			}
			private void BeginFigure(Point startPoint)
			{
				this.FinishFigure(false);
				this.EnsureFigure();
				this.figure.set_StartPoint(startPoint);
				this.figure.set_IsFilled(true);
			}
			private void EnsureFigure()
			{
				if (this.figure == null)
				{
					this.figure = new PathFigure();
					this.figure.set_Segments(new PathSegmentCollection());
				}
			}
			private void FinishFigure(bool figureExplicitlyClosed)
			{
				if (this.figure != null)
				{
					if (figureExplicitlyClosed)
					{
						this.figure.set_IsClosed(true);
					}
					this.geometry.get_Figures().Add(this.figure);
					this.figure = null;
				}
			}
			private void LineTo(Point point)
			{
				LineSegment lineSegment = new LineSegment();
				lineSegment.set_Point(point);
				this.figure.get_Segments().Add(lineSegment);
			}
			private void BezierTo(Point point1, Point point2, Point point3)
			{
				BezierSegment bezierSegment = new BezierSegment();
				bezierSegment.set_Point1(point1);
				bezierSegment.set_Point2(point2);
				bezierSegment.set_Point3(point3);
				this.figure.get_Segments().Add(bezierSegment);
			}
			private void QuadraticBezierTo(Point point1, Point point2)
			{
				QuadraticBezierSegment quadraticBezierSegment = new QuadraticBezierSegment();
				quadraticBezierSegment.set_Point1(point1);
				quadraticBezierSegment.set_Point2(point2);
				this.figure.get_Segments().Add(quadraticBezierSegment);
			}
			private void ArcTo(Size size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection, Point point)
			{
				ArcSegment arcSegment = new ArcSegment();
				arcSegment.set_Size(size);
				arcSegment.set_RotationAngle(rotationAngle);
				arcSegment.set_IsLargeArc(isLargeArc);
				arcSegment.set_SweepDirection(sweepDirection);
				arcSegment.set_Point(point);
				this.figure.get_Segments().Add(arcSegment);
			}
			private Point GetSmoothBeizerFirstPoint()
			{
				Point result = this.lastPoint;
				if (this.figure.get_Segments().get_Count() > 0)
				{
					BezierSegment bezierSegment = this.figure.get_Segments().get_Item(this.figure.get_Segments().get_Count() - 1) as BezierSegment;
					if (bezierSegment != null)
					{
						Point point = bezierSegment.get_Point2();
						result.set_X(result.get_X() + (this.lastPoint.get_X() - point.get_X()));
						result.set_Y(result.get_Y() + (this.lastPoint.get_Y() - point.get_Y()));
					}
				}
				return result;
			}
		}
		internal static PathGeometry ConvertToPathGeometry(string abbreviatedGeometry)
		{
			if (abbreviatedGeometry == null)
			{
				throw new ArgumentNullException("abbreviatedGeometry");
			}
			PathGeometry pathGeometry = new PathGeometry();
			pathGeometry.set_Figures(new PathFigureCollection());
			int num = 0;
			while (num < abbreviatedGeometry.get_Length() && char.IsWhiteSpace(abbreviatedGeometry, num))
			{
				num++;
			}
			if (num < abbreviatedGeometry.get_Length() && abbreviatedGeometry.get_Chars(num) == 'F')
			{
				num++;
				while (num < abbreviatedGeometry.get_Length() && char.IsWhiteSpace(abbreviatedGeometry, num))
				{
					num++;
				}
				if (num != abbreviatedGeometry.get_Length())
				{
					if (abbreviatedGeometry.get_Chars(num) == '0' || abbreviatedGeometry.get_Chars(num) == '1')
					{
						pathGeometry.set_FillRule((abbreviatedGeometry.get_Chars(num) == '0') ? 0 : 1);
						num++;
						goto IL_AB;
					}
				}
				throw new FormatException();
			}
			IL_AB:
			new PathGeometryHelper.AbbreviatedGeometryParser(pathGeometry).Parse(abbreviatedGeometry, num);
			return pathGeometry;
		}
		public static PathGeometry AsPathGeometry(this Geometry original)
		{
			PathGeometry pathGeometry = original as PathGeometry;
			if (pathGeometry == null && (pathGeometry = PathGeometryHelper.ConvertToPathGeometry(original as RectangleGeometry)) == null && (pathGeometry = PathGeometryHelper.ConvertToPathGeometry(original as EllipseGeometry)) == null && (pathGeometry = PathGeometryHelper.ConvertToPathGeometry(original as LineGeometry)) == null && (pathGeometry = PathGeometryHelper.ConvertToPathGeometry(original as GeometryGroup)) == null)
			{
				return null;
			}
			return pathGeometry;
		}
		public static bool IsStroked(this PathSegment pathSegment)
		{
			return true;
		}
		public static bool IsSmoothJoin(this PathSegment pathSegment)
		{
			return false;
		}
		public static bool IsFrozen(this Geometry geometry)
		{
			return true;
		}
		public static bool SyncPolylineGeometry(ref Geometry geometry, IList<Point> points, bool isClosed)
		{
			bool flag = false;
			PathGeometry pathGeometry = geometry as PathGeometry;
			PathFigure figure;
			if (pathGeometry == null || pathGeometry.get_Figures().get_Count() != 1 || (figure = pathGeometry.get_Figures().get_Item(0)) == null)
			{
				geometry = (pathGeometry = new PathGeometry());
				pathGeometry.get_Figures().Add(figure = new PathFigure());
				flag = true;
			}
			return flag | PathFigureHelper.SyncPolylineFigure(figure, points, isClosed, true);
		}
		internal static Geometry FixPathGeometryBoundary(Geometry geometry)
		{
			PathGeometry pathGeometry = geometry as PathGeometry;
			if (pathGeometry != null)
			{
				PathFigureCollection figures = pathGeometry.get_Figures();
				pathGeometry.set_Figures(null);
				pathGeometry = PathGeometryHelper.ClonePathGeometry(pathGeometry);
				pathGeometry.set_Figures(figures);
				geometry = pathGeometry;
			}
			return geometry;
		}
		public static Geometry CloneCurrentValue(this Geometry geometry)
		{
			if (geometry == null)
			{
				return null;
			}
			PathGeometry pathGeometry = geometry as PathGeometry;
			if (pathGeometry != null)
			{
				return PathGeometryHelper.ClonePathGeometry(pathGeometry);
			}
			LineGeometry lineGeometry = geometry as LineGeometry;
			if (lineGeometry != null)
			{
				return PathGeometryHelper.CloneLineGeometry(lineGeometry);
			}
			EllipseGeometry ellipseGeometry = geometry as EllipseGeometry;
			if (ellipseGeometry != null)
			{
				return PathGeometryHelper.CloneEllipseGeometry(ellipseGeometry);
			}
			RectangleGeometry rectangleGeometry = geometry as RectangleGeometry;
			if (rectangleGeometry != null)
			{
				return PathGeometryHelper.CloneRectangleGeometry(rectangleGeometry);
			}
			GeometryGroup geometryGroup = geometry as GeometryGroup;
			if (geometryGroup != null)
			{
				return PathGeometryHelper.CloneGeometryGroup(geometryGroup);
			}
			return geometry.DeepCopy<Geometry>();
		}
		private static PathGeometry ClonePathGeometry(PathGeometry pathGeometry)
		{
			PathGeometry pathGeometry2 = new PathGeometry();
			pathGeometry2.set_FillRule(pathGeometry.get_FillRule());
			pathGeometry2.set_Transform(pathGeometry.get_Transform().CloneTransform());
			PathGeometry pathGeometry3 = pathGeometry2;
			using (IEnumerator<PathFigure> enumerator = pathGeometry.get_Figures().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					PathFigure current = enumerator.get_Current();
					pathGeometry3.get_Figures().Add(PathGeometryHelper.ClonePathFigure(current));
				}
			}
			return pathGeometry3;
		}
		private static PathFigure ClonePathFigure(PathFigure pathFigure)
		{
			PathFigure pathFigure2 = new PathFigure();
			pathFigure2.set_IsClosed(pathFigure.get_IsClosed());
			pathFigure2.set_IsFilled(pathFigure.get_IsFilled());
			pathFigure2.set_StartPoint(pathFigure.get_StartPoint());
			PathFigure pathFigure3 = pathFigure2;
			using (IEnumerator<PathSegment> enumerator = pathFigure.get_Segments().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					PathSegment current = enumerator.get_Current();
					pathFigure3.get_Segments().Add(PathGeometryHelper.ClonePathSegment(current));
				}
			}
			return pathFigure3;
		}
		private static PathSegment ClonePathSegment(PathSegment pathSegment)
		{
			if (pathSegment == null)
			{
				return null;
			}
			LineSegment lineSegment = pathSegment as LineSegment;
			if (lineSegment != null)
			{
				return PathGeometryHelper.CloneLineSegment(lineSegment);
			}
			BezierSegment bezierSegment = pathSegment as BezierSegment;
			if (bezierSegment != null)
			{
				return PathGeometryHelper.CloneBezierSegment(bezierSegment);
			}
			QuadraticBezierSegment quadraticBezierSegment = pathSegment as QuadraticBezierSegment;
			if (quadraticBezierSegment != null)
			{
				return PathGeometryHelper.CloneQuadraticBezierSegment(quadraticBezierSegment);
			}
			ArcSegment arcSegment = pathSegment as ArcSegment;
			if (arcSegment != null)
			{
				return PathGeometryHelper.CloneArcSegment(arcSegment);
			}
			PolyLineSegment polyLineSegment = pathSegment as PolyLineSegment;
			if (polyLineSegment != null)
			{
				return PathGeometryHelper.ClonePolyLineSegment(polyLineSegment);
			}
			PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment;
			if (polyBezierSegment != null)
			{
				return PathGeometryHelper.ClonePolyBezierSegment(polyBezierSegment);
			}
			PolyQuadraticBezierSegment polyQuadraticBezierSegment = pathSegment as PolyQuadraticBezierSegment;
			if (polyQuadraticBezierSegment != null)
			{
				return PathGeometryHelper.ClonePolyQuadraticBezierSegment(polyQuadraticBezierSegment);
			}
			return pathSegment.DeepCopy<PathSegment>();
		}
		private static LineSegment CloneLineSegment(LineSegment lineSegment)
		{
			LineSegment lineSegment2 = new LineSegment();
			lineSegment2.set_Point(lineSegment.get_Point());
			return lineSegment2;
		}
		private static BezierSegment CloneBezierSegment(BezierSegment bezierSegment)
		{
			BezierSegment bezierSegment2 = new BezierSegment();
			bezierSegment2.set_Point1(bezierSegment.get_Point1());
			bezierSegment2.set_Point2(bezierSegment.get_Point2());
			bezierSegment2.set_Point3(bezierSegment.get_Point3());
			return bezierSegment2;
		}
		private static QuadraticBezierSegment CloneQuadraticBezierSegment(QuadraticBezierSegment quadraticBezierSegment)
		{
			QuadraticBezierSegment quadraticBezierSegment2 = new QuadraticBezierSegment();
			quadraticBezierSegment2.set_Point1(quadraticBezierSegment.get_Point1());
			quadraticBezierSegment2.set_Point2(quadraticBezierSegment.get_Point2());
			return quadraticBezierSegment2;
		}
		private static ArcSegment CloneArcSegment(ArcSegment arcSegment)
		{
			ArcSegment arcSegment2 = new ArcSegment();
			arcSegment2.set_IsLargeArc(arcSegment.get_IsLargeArc());
			arcSegment2.set_Point(arcSegment.get_Point());
			arcSegment2.set_RotationAngle(arcSegment.get_RotationAngle());
			arcSegment2.set_Size(arcSegment.get_Size());
			arcSegment2.set_SweepDirection(arcSegment.get_SweepDirection());
			return arcSegment2;
		}
		private static PolyLineSegment ClonePolyLineSegment(PolyLineSegment polyLineSegment)
		{
			PolyLineSegment polyLineSegment2 = new PolyLineSegment();
			using (IEnumerator<Point> enumerator = polyLineSegment.get_Points().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Point current = enumerator.get_Current();
					polyLineSegment2.get_Points().Add(current);
				}
			}
			return polyLineSegment2;
		}
		private static PolyBezierSegment ClonePolyBezierSegment(PolyBezierSegment polyBezierSegment)
		{
			PolyBezierSegment polyBezierSegment2 = new PolyBezierSegment();
			using (IEnumerator<Point> enumerator = polyBezierSegment.get_Points().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Point current = enumerator.get_Current();
					polyBezierSegment2.get_Points().Add(current);
				}
			}
			return polyBezierSegment2;
		}
		private static PolyQuadraticBezierSegment ClonePolyQuadraticBezierSegment(PolyQuadraticBezierSegment polyQuadraticBezierSegment)
		{
			PolyQuadraticBezierSegment polyQuadraticBezierSegment2 = new PolyQuadraticBezierSegment();
			using (IEnumerator<Point> enumerator = polyQuadraticBezierSegment.get_Points().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Point current = enumerator.get_Current();
					polyQuadraticBezierSegment2.get_Points().Add(current);
				}
			}
			return polyQuadraticBezierSegment2;
		}
		private static EllipseGeometry CloneEllipseGeometry(EllipseGeometry ellipseGeometry)
		{
			EllipseGeometry ellipseGeometry2 = new EllipseGeometry();
			ellipseGeometry2.set_Center(ellipseGeometry.get_Center());
			ellipseGeometry2.set_RadiusX(ellipseGeometry.get_RadiusX());
			ellipseGeometry2.set_RadiusY(ellipseGeometry.get_RadiusY());
			ellipseGeometry2.set_Transform(ellipseGeometry.get_Transform().CloneTransform());
			return ellipseGeometry2;
		}
		private static RectangleGeometry CloneRectangleGeometry(RectangleGeometry rectangleGeometry)
		{
			RectangleGeometry rectangleGeometry2 = new RectangleGeometry();
			rectangleGeometry2.set_Rect(rectangleGeometry.get_Rect());
			rectangleGeometry2.set_RadiusX(rectangleGeometry.get_RadiusX());
			rectangleGeometry2.set_RadiusY(rectangleGeometry.get_RadiusY());
			rectangleGeometry2.set_Transform(rectangleGeometry.get_Transform().CloneTransform());
			return rectangleGeometry2;
		}
		private static LineGeometry CloneLineGeometry(LineGeometry lineGeometry)
		{
			LineGeometry lineGeometry2 = new LineGeometry();
			lineGeometry2.set_StartPoint(lineGeometry.get_StartPoint());
			lineGeometry2.set_EndPoint(lineGeometry.get_EndPoint());
			lineGeometry2.set_Transform(lineGeometry.get_Transform().CloneTransform());
			return lineGeometry2;
		}
		private static GeometryGroup CloneGeometryGroup(GeometryGroup geometryGroup)
		{
			GeometryGroup geometryGroup2 = new GeometryGroup();
			geometryGroup2.set_FillRule(geometryGroup.get_FillRule());
			geometryGroup2.set_Transform(geometryGroup.get_Transform().CloneTransform());
			GeometryGroup geometryGroup3 = geometryGroup2;
			using (IEnumerator<Geometry> enumerator = geometryGroup.get_Children().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Geometry current = enumerator.get_Current();
					geometryGroup3.get_Children().Add(current.CloneCurrentValue());
				}
			}
			return geometryGroup3;
		}
		private static PathGeometry ConvertToPathGeometry(EllipseGeometry ellipseGeometry)
		{
			if (ellipseGeometry != null)
			{
				Rect bounds = ellipseGeometry.get_Bounds();
				if (bounds.Size().HasValidArea())
				{
					Point point = GeometryHelper.Lerp(bounds.TopLeft(), bounds.TopRight(), 0.5);
					Point point2 = GeometryHelper.Lerp(bounds.BottomLeft(), bounds.BottomRight(), 0.5);
					Size size = new Size(ellipseGeometry.get_RadiusX(), ellipseGeometry.get_RadiusY());
					PathGeometry pathGeometry = new PathGeometry();
					pathGeometry.set_Transform(ellipseGeometry.get_Transform());
					PathGeometry arg_11D_0 = pathGeometry;
					PathFigureCollection pathFigureCollection = new PathFigureCollection();
					PresentationFrameworkCollection<PathFigure> arg_116_0 = pathFigureCollection;
					PathFigure pathFigure = new PathFigure();
					pathFigure.set_StartPoint(point);
					pathFigure.set_IsClosed(true);
					pathFigure.set_IsFilled(true);
					PathFigure arg_10F_0 = pathFigure;
					PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
					PresentationFrameworkCollection<PathSegment> arg_D8_0 = pathSegmentCollection;
					ArcSegment arcSegment = new ArcSegment();
					arcSegment.set_Point(point2);
					arcSegment.set_IsLargeArc(true);
					arcSegment.set_Size(size);
					arcSegment.set_SweepDirection(1);
					arg_D8_0.Add(arcSegment);
					PresentationFrameworkCollection<PathSegment> arg_108_0 = pathSegmentCollection;
					ArcSegment arcSegment2 = new ArcSegment();
					arcSegment2.set_Point(point);
					arcSegment2.set_IsLargeArc(true);
					arcSegment2.set_Size(size);
					arcSegment2.set_SweepDirection(1);
					arg_108_0.Add(arcSegment2);
					arg_10F_0.set_Segments(pathSegmentCollection);
					arg_116_0.Add(pathFigure);
					arg_11D_0.set_Figures(pathFigureCollection);
					return pathGeometry;
				}
			}
			return null;
		}
		private static PathGeometry ConvertToPathGeometry(RectangleGeometry rectangleGeometry)
		{
			if (rectangleGeometry == null)
			{
				return null;
			}
			Rect bounds = rectangleGeometry.get_Bounds();
			if (!bounds.Size().HasValidArea())
			{
				return null;
			}
			PathGeometry pathGeometry = new PathGeometry();
			pathGeometry.set_Transform(rectangleGeometry.get_Transform());
			PathFigure pathFigure = new PathFigure();
			pathFigure.set_IsClosed(true);
			pathFigure.set_IsFilled(true);
			PathFigure pathFigure2 = pathFigure;
			pathGeometry.get_Figures().Add(pathFigure2);
			if (rectangleGeometry.get_RadiusX() * rectangleGeometry.get_RadiusY() == 0.0)
			{
				pathFigure2.set_StartPoint(bounds.TopLeft());
				PresentationFrameworkCollection<PathSegment> arg_BA_0 = pathFigure2.get_Segments();
				PolyLineSegment polyLineSegment = new PolyLineSegment();
				PolyLineSegment arg_B4_0 = polyLineSegment;
				PointCollection pointCollection = new PointCollection();
				pointCollection.Add(bounds.TopRight());
				pointCollection.Add(bounds.BottomRight());
				pointCollection.Add(bounds.BottomLeft());
				arg_B4_0.set_Points(pointCollection);
				arg_BA_0.Add(polyLineSegment);
				return pathGeometry;
			}
			bool flag = Math.Abs(rectangleGeometry.get_RadiusX()) < bounds.get_Width() / 2.0;
			bool flag2 = Math.Abs(rectangleGeometry.get_RadiusY()) < bounds.get_Height() / 2.0;
			double num = Math.Min(Math.Abs(rectangleGeometry.get_RadiusX()), bounds.get_Width() / 2.0);
			double num2 = Math.Min(Math.Abs(rectangleGeometry.get_RadiusY()), bounds.get_Height() / 2.0);
			Size cornerSize = new Size(num, num2);
			pathFigure2.set_StartPoint(new Point(bounds.get_Left(), bounds.get_Top() + num2));
			pathFigure2.get_Segments().Add(PathGeometryHelper.CreateCorner(new Point(bounds.get_Left() + num, bounds.get_Top()), cornerSize));
			if (flag)
			{
				PresentationFrameworkCollection<PathSegment> arg_1C6_0 = pathFigure2.get_Segments();
				LineSegment lineSegment = new LineSegment();
				lineSegment.set_Point(new Point(bounds.get_Right() - num, bounds.get_Top()));
				arg_1C6_0.Add(lineSegment);
			}
			pathFigure2.get_Segments().Add(PathGeometryHelper.CreateCorner(new Point(bounds.get_Right(), bounds.get_Top() + num2), cornerSize));
			if (flag2)
			{
				PresentationFrameworkCollection<PathSegment> arg_223_0 = pathFigure2.get_Segments();
				LineSegment lineSegment2 = new LineSegment();
				lineSegment2.set_Point(new Point(bounds.get_Right(), bounds.get_Bottom() - num2));
				arg_223_0.Add(lineSegment2);
			}
			pathFigure2.get_Segments().Add(PathGeometryHelper.CreateCorner(new Point(bounds.get_Right() - num, bounds.get_Bottom()), cornerSize));
			if (flag)
			{
				PresentationFrameworkCollection<PathSegment> arg_280_0 = pathFigure2.get_Segments();
				LineSegment lineSegment3 = new LineSegment();
				lineSegment3.set_Point(new Point(bounds.get_Left() + num, bounds.get_Bottom()));
				arg_280_0.Add(lineSegment3);
			}
			pathFigure2.get_Segments().Add(PathGeometryHelper.CreateCorner(new Point(bounds.get_Left(), bounds.get_Bottom() - num2), cornerSize));
			return pathGeometry;
		}
		private static ArcSegment CreateCorner(Point endPoint, Size cornerSize)
		{
			ArcSegment arcSegment = new ArcSegment();
			arcSegment.set_IsLargeArc(false);
			arcSegment.set_SweepDirection(1);
			arcSegment.set_Point(endPoint);
			arcSegment.set_Size(cornerSize);
			return arcSegment;
		}
		private static PathGeometry ConvertToPathGeometry(LineGeometry lineGeometry)
		{
			if (lineGeometry != null)
			{
				Rect bounds = lineGeometry.get_Bounds();
				if (bounds.Size().HasValidArea())
				{
					PathGeometry pathGeometry = new PathGeometry();
					pathGeometry.set_Transform(lineGeometry.get_Transform());
					PathGeometry arg_87_0 = pathGeometry;
					PathFigureCollection pathFigureCollection = new PathFigureCollection();
					PresentationFrameworkCollection<PathFigure> arg_81_0 = pathFigureCollection;
					PathFigure pathFigure = new PathFigure();
					pathFigure.set_StartPoint(lineGeometry.get_StartPoint());
					pathFigure.set_IsClosed(false);
					pathFigure.set_IsFilled(false);
					PathFigure arg_7B_0 = pathFigure;
					PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
					PresentationFrameworkCollection<PathSegment> arg_74_0 = pathSegmentCollection;
					LineSegment lineSegment = new LineSegment();
					lineSegment.set_Point(lineGeometry.get_EndPoint());
					arg_74_0.Add(lineSegment);
					arg_7B_0.set_Segments(pathSegmentCollection);
					arg_81_0.Add(pathFigure);
					arg_87_0.set_Figures(pathFigureCollection);
					return pathGeometry;
				}
			}
			return null;
		}
		private static PathGeometry ConvertToPathGeometry(GeometryGroup geometryGroup)
		{
			if (geometryGroup != null)
			{
				Rect bounds = geometryGroup.get_Bounds();
				if (bounds.Size().HasValidArea())
				{
					PathGeometry pathGeometry = new PathGeometry();
					pathGeometry.SetIfDifferent(PathGeometry.FillRuleProperty, geometryGroup.get_FillRule());
					LinkedList<Geometry> linkedList = new LinkedList<Geometry>();
					linkedList.AddLast(geometryGroup);
					while (linkedList.get_Count() > 0)
					{
						LinkedListNode<Geometry> first = linkedList.get_First();
						Geometry value = first.get_Value();
						GeometryGroup geometryGroup2 = value as GeometryGroup;
						if (geometryGroup2 != null)
						{
							using (IEnumerator<Geometry> enumerator = geometryGroup2.get_Children().GetEnumerator())
							{
								while (enumerator.MoveNext())
								{
									Geometry current = enumerator.get_Current();
									linkedList.AddAfter(first, current);
								}
								goto IL_F9;
							}
							goto IL_A4;
						}
						goto IL_A4;
						IL_F9:
						linkedList.RemoveFirst();
						continue;
						IL_A4:
						PathGeometry pathGeometry2 = value.AsPathGeometry();
						if (pathGeometry2 != null)
						{
							for (int i = pathGeometry2.get_Figures().get_Count() - 1; i >= 0; i--)
							{
								PathFigure pathFigure = pathGeometry2.get_Figures().get_Item(i);
								pathGeometry2.get_Figures().RemoveAt(i);
								pathGeometry.get_Figures().Add(pathFigure);
							}
							goto IL_F9;
						}
						goto IL_F9;
					}
					return pathGeometry;
				}
			}
			return null;
		}
	}
}
